{% extends "index.html" %}

{% block content %}


	
	

	 
		<div class="col-xs-12">
			<h3 class="header smaller lighter blue">
			<i class="icon-hand-right icon-animated-hand-pointer blue"></i>
			DHCP服务配置</h3>
			
						<div class="col-sm-4">
										<div class="widget-box">
											<div class="widget-header widget-header-flat">
												<h4>Tips</h4>
											</div>

											<div class="widget-body">
												<div class="widget-main">
													<ul class="list-unstyled spaced2">
														<li>
															<i class="icon-circle green"></i>
															该功用来配置全局DHCP服务
														</li>
							
														<li >
															<i class="icon-ok bigger-110 green"></i>
															提供内网，外网DHCP功能
														</li>
							
															<li class="muted">
																<i class="icon-warning-sign orange"></i>
																请在桥接环境下使用：
																								
															</li>
						
															<li>
																<ul class="list-unstyled">
																	<li>
																		<i class="icon-caret-right blue"></i>
																		如果局域网已经存在DHCP，请分配不同IP段的地址，以免造成冲突。
																	</li>
						
																	<li>
																		<i class="icon-caret-right blue"></i>
																		内网DHCP服务，不需要分配路由与DNS
																	</li>
																	<li>
																		<i class="icon-caret-right blue"></i>
																		尽量使用C类地址，注意dhcp地址要设置掩码
																	</li>
						
																</ul>
															</li>																																																																																																											
														</ul>														
												</div>
											</div>
										</div>
									</div>
			<div class="col-sm-8">
			<div class="table-header"></div>		
			<div class="tabbable">
				<ul class="nav nav-tabs padding-12 tab-color-blue background-blue" id="myTab4">
					<li class="active">
						<a data-toggle="tab" href="#dropdown14">DHCP列表</a>
					</li>
					<li>
						<a data-toggle="tab" href="#profile4">配置DHCP</a>
					</li>
				</ul>

				<div class="tab-content">

						<div id="profile4" class="tab-pane">
								
													<form class="form-horizontal" id="addNetwork">

																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="email"><strong>网络类型:</strong></label>
						
																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<select id="vNetwork-select" name="mode" onchange="javascript:oBtModeTypeSelect();">
																				<option value="">选择网络类型</option>
																				<option value="dhcp-int">内网</option>	
																				<option value="dhcp-ext">外网</option>																		
																			</select>
																		</div>
																	</div>																							
																</div>																										
						
																<div class="form-group">
																	<label class="control-label col-xs-12 col-sm-3 no-padding-right" for="email"><strong>驱动类型:</strong></label>
						
																	<div class="col-xs-12 col-sm-9">
																		<div class="clearfix">
																			<select id="vDrive-select" name="drive">
																				<option value="">选择网络驱动类型</option>
																				<option value="ovs">Open Vswitch</option>	
																				<option value="brctl">Linux Brctl</option>																		
																			</select>
																		</div>
																	</div>																							
																</div>										

																<div class="form-group">
																	<label class="col-sm-3 control-label no-padding-right" for="form-field-4"><strong>绑定网桥</strong></label>
							
																	<div class="col-sm-9">
																		<input class="input-sm" type="text" id="form-field-6" placeholder="ovs-int" name="brName" />																																					
																	</div>
																</div>	

																<div class="form-group">
																	<label class="col-sm-3 control-label no-padding-right" for="form-field-4"><strong>DHCP服务地址</strong></label>
							
																	<div class="col-sm-9">
																		<input class="input-sm" type="text" id="form-field-6" placeholder="192.168.1.1" name="server_ip" />																																					
																	</div>
																</div>	
																<div class="form-group">
																	<label class="col-sm-3 control-label no-padding-right" for="form-field-4"><strong>掩码位</strong></label>
							
																	<div class="col-sm-9">
																		<input class="input-sm" type="text" id="form-field-6" placeholder="24" name="mask" />																																					
																	</div>
																</div>																							
						
																<div class="form-group" style="display:none;" id="div_ext_iprange">
																	<label class="col-sm-3 control-label no-padding-right" for="form-field-4"><strong>网络地址池</strong></label>
							
																	<div class="col-sm-9">
																		<input class="input-sm" type="text" id="form-field-6" placeholder="192.168.1.100,192.168.1.254" name="ext-iprange" />		
																																			
																	</div>
																</div>

																<div class="form-group" style="display:none;" id="div_ext_gateway">
																	<label class="col-sm-3 control-label no-padding-right" for="form-field-4"><strong>网关地址</strong></label>
							
																	<div class="col-sm-9">
																				
																		<input class="input-sm" type="text" id="form-field-6" placeholder="192.168.1.1" name="gateway" />																		
																	</div>
																</div>
																
																<div class="form-group" style="display:none;" id="div_int_iprange">
																	<label class="col-sm-3 control-label no-padding-right" for="form-field-4"><strong>网络地址池</strong></label>
							
																	<div class="col-sm-6">
																		<input class="input-sm" type="text" id="form-field-6" placeholder="172.16.0.100,172.16.0.254" name="int-iprange" />		
																	
																	</div>
																</div>																
																
																<div class="form-group" style="display:none;" id="div_ext_dns">
																	<label class="col-sm-3 control-label no-padding-right" for="form-field-4"><strong>DNS</strong></label>
							
																	<div class="col-sm-9">
																		<input class="input-sm" type="text" id="form-field-6" placeholder="114.114.114.114" name="dns" />																				
																	</div>
																</div>																

																		
							
																<div class="hr hr32 hr-dotted"></div>
																<div class="form-group">
																	<div class="col-md-offset-3 col-md-9">
																		<button class="btn btn-info" type="button" onclick="addGlobalDHCP(this)">
																			<i class="icon-ok bigger-110"></i>
																			提交
																		</button>
							
																		&nbsp; &nbsp; &nbsp;
																		<button class="btn" type="reset">
																			<i class="icon-undo bigger-110"></i>
																			撤销
																		</button>
																	</div>
																</div>	
																															
															</form>																	
								
						</div>

						<div id="dropdown14" class="tab-pane in active">
	
													<div>
														<table class="table table-striped table-bordered">
															<thead>
																<tr>
																	<th class="center">序号</th>
																	<th class="center">DHCP类型</th>
																	<th class="hidden-xs center">驱动类型</th>
																	<th class="hidden-xs center">网桥绑定</th>
																	<th class="hidden-480 center">ip地址池</th>
																	<th class="center">服务地址</th>
																	<th class="center">网关</th>
																	<th class="center">DNS</th>
																	<th class="center">是否激活</th>
																	<th class="center">是否启动</th>
																	<th class="center">操作</th>
																</tr>
															</thead>
										
															<tbody>
																{% for ds in dataList %}
																<tr>
																	<td class="center">{{ ds.id }}</td>
																	<td class="center">
																		<a>{{ ds.mode }}</a>
																	</td>
																		<td class="hidden-xs center">
																			{{ ds.drive }}								
																	</td>
																	<td class="center">
																			{{ ds.brName }}																		
																	</td>
																	<td class="center">
																			{{ ds.ip_range }}																		
																	</td>
																	<td class="center">
																			{{ ds.server_ip }}																		
																	</td>
																	<td class="center">
																			{{ ds.gateway }}																		
																	</td>	
																	<td class="center">
																			{{ ds.dns }}																		
																	</td>	
																	<td class="center">
																		{% if ds.isAlive == 1 %}
																		<button class="btn btn-xs btn-danger" onclick="onBtnHandleGlobalNetwork(this,{{ ds.id}},'{{ds.mode}}','enable')">
																			No
																		</button>															
																		{% elif ds.isAlive == 0 %}
																		<button class="btn btn-xs btn-success" onclick="onBtnHandleGlobalNetwork(this,{{ ds.id }},'{{ds.mode}}','disable')">
																			Yes
																		</button>																				
																		{% endif %}																	
																	</td>	
																	<td class="center">
																		{% if ds.status == 0 %}
																		<span class="label label-danger arrowed">Off</span>															
																		{% elif ds.status == 1 %}
																		<span class="label label-success arrowed-in">On</span>																				
																		{% endif %}	
																	</td>														
																	<td>
																		
																		<div class="btn-group">
																			<button data-toggle="dropdown" class="btn btn-warning btn-sm dropdown-toggle">
																				<i class="icon-wrench  bigger-110 icon-only"> </i>
																				<span class="icon-caret-down icon-on-right"></span>
																			</button>
							
																			<ul class="dropdown-menu dropdown-info pull-right">
																				<li>
																					<a href="javascript:" onclick="onBtnHandleGlobalNetwork(this,{{ ds.id }},'{{ds.mode}}','start')">
																					
																					启动
																					</a>
																				</li>	
																						
																				<li>
																					<a href="javascript:" onclick="onBtnHandleGlobalNetwork(this,{{ ds.id }},'{{ds.mode}}','stop')">
																					
																					停止
																					</a>
																				</li>											
																				<li class="divider"></li>
																			
							
																				<li>
																					<a href="javascript:" onclick="onBtnHandleGlobalNetwork(this,{{ ds.id }},'{{ds.mode}}','delete')">
																						
																						删除
																					</a>
																				</li>
																			</ul>
																		</div>										
																	</td>
																</tr>
																{% endfor %}
															</tbody>
														</table>
													</div>													
													<div class="hr "></div>
										
													<div class="row">
														<div class="col-sm-5 pull-right">
															<h4 class="pull-right">
																Total DHCP Service:
																<span class="red">{{ dataList|length }}</span>
															</h4>
														</div>
														<div class="col-sm-7 pull-left"> 汇总信息 </div>
													</div>							
																
						</div>
				</div>
			</div>
		</div>	
	 </div>	
	

										
			
	
		
			



	<script type="text/javascript">
			var required = ['mode','server_ip','drive','brName','mask']
			   function oBtModeTypeSelect() {
				   var obj = document.getElementById("vNetwork-select"); 
				   var index = obj.selectedIndex;
				   var value = obj.options[index].value; 
				   if (value=="dhcp-int"){
					   required = ['mode','server_ip','drive','int-iprange','brName','mask']
					   document.getElementById("div_int_iprange").style.display="";
					   document.getElementById("div_ext_iprange").style.display="none";
					   document.getElementById("div_ext_dns").style.display="none";
					   document.getElementById("div_ext_gateway").style.display="none";
				   }			   
				   else if (value=="dhcp-ext"){
					   required = ['mode','server_ip','drive','ext-iprange','gateway','dns','brName','mask']
					   document.getElementById("div_ext_iprange").style.display="";
					   document.getElementById("div_int_iprange").style.display="none";
					   document.getElementById("div_ext_dns").style.display="";
					   document.getElementById("div_ext_gateway").style.display="";
	
				   }			   
			   }
			   
				function addGlobalDHCP(obj) {
					var server_data = {}
					var form = document.getElementById('addNetwork');
					for (var i = 0; i < form.length; ++i) {
						var name = form[i].name;
						var value = form[i].value;	
						idx = $.inArray(name, required);						
						if (idx >= 0 && value.length == 0){
							window.wxc.xcConfirm("请注意必填项不能为空~", window.wxc.xcConfirm.typeEnum.error);
							return false;
						};	
						if ( idx >= 0 && value.length != 0 && name.length != 0 ){						
							server_data[name] = value;
						};					
					};		
					$.ajax({
						dataType: "JSON",
						url:'/configDhcp/', //请求地址
						type:"POST",  //提交类似
						data:server_data,  //提交参数
						success:function(response){
							if (response["code"] == 200){
								window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.success);
								location.reload();
							}
							else {
								window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
							}
							
						},
				    	error:function(response){
				    		window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
				    	}
					})	
				}	
				
				   function onBtnHandleGlobalNetwork(obj, dhcp_id,mode,op){
						var btnObj = $(obj);	
						if( op == 'enable' ){
							var txt=  "是否确认激活（"+mode+"）?"
						}	
						else if( op == 'start' ){
							var txt=  "是否确认启动（"+mode+"）?"
						}	
						else if( op == 'stop' ){
							var txt=  "是否确认关闭（"+mode+"）?"
						}
						else if( op == 'delete' ){
							var txt=  "是否确认删除（"+mode+"）?"
						}						
						else if( op == 'disable' ){
							var txt=  "是否确认禁用（"+mode+"）?"
						};						
						var option = {
								title: "操作("+mode+")",
								btn: parseInt("0011",2),
								onOk: function(){
									$.ajax({
										  type: 'POST',
										  url: '/handleDhcp/',
										  data:{
												"id":dhcp_id,
												"op":op,							
											},
									      success:function(response){			            
								                if (response["code"]=="200"){ 
								                	window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.success);
								                	location.reload();
								                }
									        	else{
									        		window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
									        	}						                
										},
							            error:function(response){
							            	window.wxc.xcConfirm(response["msg"], window.wxc.xcConfirm.typeEnum.error);
							            },		
										});
								},
								onCancel:function(){	
								},
								onClose:function(){
								}
							}			
						window.wxc.xcConfirm(txt, "custom", option);
					}				
			   
	</script>

{% endblock %}